package com.example.mbl.controller;

import com.example.mbl.entity.Article;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.ArticlePageResult;
import com.example.mbl.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("Article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @AppToken
    @PostMapping("addArticle")
    public WebRestResult addArticle(@RequestBody Article article){
        WebRestResult result = articleService.addArticle(article);
        return result;
    }

    @AppToken
    @PostMapping("deleteArticle")
    public WebRestResult deleteArticle(@RequestBody Article article){
        WebRestResult result = articleService.deleteArticle(article);
        return result;
    }

    @AppToken
    @PostMapping("updateArticle")
    public WebRestResult updateArticle(@RequestBody Article article){
        WebRestResult result = articleService.updateArticle(article);
        return result;
    }

    @AppToken
    @PostMapping("setArticleVisible")
    public WebRestResult setArticleVisible(@RequestBody Article article){
        WebRestResult result = articleService.setArticleVisible(article);
        return result;
    }

    @GetMapping("getArticleList")
    public PageResult<ArticlePageResult> getArticleList(String title,String publishdate,int page,int pagesize){
        PageResult<ArticlePageResult> result = articleService.getArticleList(title,publishdate,page,pagesize);
        return result;
    }
}
